package ru.ifmo.kis;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import java.util.logging.Logger;

/**
 * Used only with standalone application. Web uses spring AOP hibernate session injection.
 */
public class HibernateUtil {
	private static final Logger log = Logger.getLogger(HibernateUtil.class.toString());

	private static final SessionFactory sessionFactory;

	static {
		try {
			// Create the SessionFactory from hibernate.cfg.xml
			sessionFactory = new AnnotationConfiguration()
					.configure("/hibernate.cfg.xml")
					.buildSessionFactory();
		} catch (Throwable ex) {
			log.severe("Initial SessionFactory creation failed.");
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}

}